package _36define;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Demo {
    public static void main(String[] args) throws Exception {
        Student[] students=new Student[10];
        Scanner sc=new Scanner(System.in);
        int i=0;
        while (i<10){
            String a=sc.nextLine();
            if (a.equals("exit")){
                break;
            }
            String[] arr=a.split(";");
            students[i]=new Student(Integer.parseInt(arr[0]),arr[1],Integer.parseInt(arr[2]));
            i++;
        }
        List<Student> list=new ArrayList<>();
        for (Student s : students) {
            if (s!=null){
                list.add(s);
            }
        }
        Student[] students1=list.toArray(new Student[0]);
        Arrays.sort(students1);
        OutputStreamWriter out =new OutputStreamWriter(new FileOutputStream("src/a.txt"));
        for (Student student : students1) {
            if (student!=null){
                String s=student.toString();
                char[] chars=s.toCharArray();
                out.write(chars);
                out.write("\t\r");
            }
        }
        out.close();

    }
}
class Student implements Comparable<Student>{
    int id;
    String name;
    int age;

    public Student(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Student o1) {
        return Integer.compare(this.age, o1.age);
    }
}
